<?php 
define('IN_WONDERSHARE', true);
header("Content-type:text/html;charset=utf-8");
ob_start("ob_gzhandler");
require('../includes/init.php');
require('./classes/control/control_products_page.php');

class ProductsPage
{
	var $products_page_c;
	var $webType;//网站类型
	function __construct(){
	
		$this->products_page_c = new ProductsPageControl();
		$this->webType = empty($_REQUEST['web_type'])?1:(int)trim($_REQUEST['web_type']);
	}
	//产品页面管理
	function index()
	{
		if($_GET['in_jax'] == 1)
		{
			$type = $_GET['type'];
			$value = $_GET['value'];
			switch($type) 
			{
				case 'page_sort':
				$field = 'sort';
				break;
			}
			if (!empty($_GET['page_id']))
				echo  $this->products_page_c->change_info((int)$_GET['page_id'],$value,$field);
		}elseif($_REQUEST['act'] == 'edit')//修改
		{
			$products_page_info = array();
			$products_id = !empty($_REQUEST['ws_products_id']) ? intval($_REQUEST['ws_products_id']): 0;
			if($_POST['sub_from'])
			{
				if(!empty($_POST['page_id']))
				{
					$affect = $this->products_page_c->update_products_page((int)$_POST['page_id'],$_POST['title'],$_POST['content']);
					if($affect == 1)
					{
						echo  '<script > alert("修改成功！");
						window.location.href="/wondershare/products_page.php?action=index&web_type='.
						$this->webType.'&ws_products_id='.$products_id.'"; </script>';
						
						$update_arr = array('id' =>(int) $products_id,//won_product表id
											'w_type' => $this->webType,
											'operation_type' => 'product',
											'location' => '/wondershare/products_page.php?action=index&web_type='.$this->webType.'&ws_products_id='.$products_id,
						);
						
					 	echo '<script type="text/javascript">
							window.location.href="/wondershare/template.php?action=updateTemplate&type=update&'.http_build_query($update_arr).'";
							</script>';
					}
				}
			}
			$products_page_info = $this->products_page_c->get_products_page_info('edit',(int)$_GET['page_id']);
			$GLOBALS['smarty']->assign('web_info',   get_web_info($this->webType));
			$GLOBALS['smarty']->assign('web_type',     $this->webType);
			$GLOBALS['smarty']->assign('products_id',   $products_id);
			$GLOBALS['smarty']->assign('tile',     '修改');
			$GLOBALS['smarty']->assign('form_act',     'edit');
			$GLOBALS['smarty']->assign('page_info',$products_page_info[0] );
			$GLOBALS['smarty']->display('products_page_info.htm'); 
		}
		else
		{
			$url_info = $products_page_info = array();$product_name = '';$page = 1;
			//分页处理
			$products_id = !empty($_GET['ws_products_id'])?intval($_GET['ws_products_id']):0;
			if (!empty($_REQUEST['page'])) {
				$page = (int)$_REQUEST['page'];
			}
			$url_info = $this->products_page_c->get_url_info($page,10,$products_id);
			$products_page_info = $this->products_page_c->get_products_page_info('list',0,$url_info['page_info']['start'],10,$products_id);
			if($products_id != 0)
			$product_name = $this->products_page_c->get_product_name($products_id);
			$GLOBALS['smarty']->assign('web_info',   get_web_info($this->webType));
			$GLOBALS['smarty']->assign('web_type',     $this->webType);
			$GLOBALS['smarty']->assign('products_id',   $products_id);
			$GLOBALS['smarty']->assign('product_name',   $product_name);
			$GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
			$GLOBALS['smarty']->assign('products_page',$products_page_info );
			$GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
			
			$GLOBALS['smarty']->display('products_page_index.htm'); 
		}	
	}
}
$action    = $_REQUEST['action']; 
$products_page   = new ProductsPage;
if(method_exists($products_page, $action)) 
{
$products_page->$action();
}else{
$products_page->index();
}
	
?>
